package com.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.InlineLabel;

public class Tag extends InlineLabel {

	private HandlerRegistration hdlrReg = null;
	
	public Tag() {
		super();
		this.setStyleName("appTag");
	}
	
  public HandlerRegistration addClickHandler(ClickHandler handler) {
  	if (null != this.hdlrReg)
  		this.hdlrReg.removeHandler();
  	this.hdlrReg = super.addClickHandler(handler);
  	return this.hdlrReg;
  }

}

final class ClkAddTag implements ClickHandler {
	public void onClick(ClickEvent event) {
		Tag tag = (Tag) event.getSource();
		tag.addClickHandler(new ClkRemoveTag());
		CNStatsFront.get().plSearch.hpTags
				.remove(CNStatsFront.get().plSearch.hSearchHint);
		CNStatsFront.get().plSearch.hpTags.add(tag);
		CNStatsFront.get().plSearch.getTags();
	}
}

final class ClkRemoveTag implements ClickHandler {
	public void onClick(ClickEvent event) {
		CNStatsFront.get().plSearch.hpTags.remove((Tag) event.getSource());
		if (0 == CNStatsFront.get().plSearch.hpTags.getWidgetCount())
			CNStatsFront.get().plSearch.hpTags
					.add(CNStatsFront.get().plSearch.hSearchHint);
		CNStatsFront.get().plSearch.getTags();
	}
}
